#include <cstdlib>
#include <iostream>
#include <ctime>
#include <fstream>

using namespace std;
void version(){
	cout << "Version 0.1" << endl;
}
void createTabulaSpace(){
	srand(time(NULL));
	char temp[1];
	int counter = 2;

	//int x;
	ofstream myfile;
	myfile.open("tabulaRectaSpace.txt");
	myfile << "   ";
	for(int a = 1; a < 27; a++)
	{
		int b = a+64;
		sprintf(temp,"%c  ", b);
		myfile << temp;
	}
	myfile << "\n\nA  ";
	for(int i = 1; i < 677; i++){
		int random = (rand()%94)+32;
		if(random == 32 || random == 34){
			random = random + ((rand()%10)+1);
			if (random == 34)
				random++;
		}
		//cout << "The Value of RAND_MAX is " << RAND_MAX << endl;
		//cout << "Random number " << random << endl;
		int y = sprintf(temp,"%c  ",random);
		myfile << temp;
		int z = i % 26;
		if(z == 0 && i != 676){
			myfile << "\n\n";
			int c = counter+64;
			cout << c << endl;
			sprintf(temp,"%c  ",c);
			cout << temp << endl;
			counter++;
			myfile << temp;
		}
	}
	myfile << "\n\n";
	myfile << "Tabula recta creator\nCopyright Brandon Smith 2011";
	myfile.close();
	// gotta wait or it will just close
	cout << "creation of your tabula recta is complete" << endl;
	cout << "Please enter 0 to quit" << endl;
}
void createTabulaTab(){
	srand(time(NULL));
	char temp[1];
	int counter = 2;

	int x;
	ofstream myfile;
	myfile.open("tabulaRectaTab.txt");
	myfile << " \t";
	for(int a = 1; a < 27; a++)
	{
		int b = a+64;
		sprintf(temp,"%c\t", b);
		myfile << temp;
	}
	myfile << "\n\nA\t";
	for(int i = 1; i < 677; i++){
		int random = (rand()%94)+32;
		if(random == 32 || random == 34){
			random = random + ((rand()%10)+1);
			if (random == 34)
				random++;
		}
		//cout << "The Value of RAND_MAX is " << RAND_MAX << endl;
		//cout << "Random number " << random << endl;
		int y = sprintf(temp,"%c\t",random);
		myfile << temp;
		int z = i % 26;
		if(z == 0 && i != 676){
			myfile << "\n\n";
			int c = counter+64;
			cout << c << endl;
			sprintf(temp,"%c\t",c);
			cout << temp << endl;
			counter++;
			myfile << temp;
		}
	}
	myfile << "\n\n";
	myfile << "Tabula recta creator\nCopyright Brandon Smith 2011";
	myfile.close();
	// gotta wait or it will just close
	cout << "creation of your tabula recta is complete" << endl;
	cout << "Please enter 0 to quit" << endl;
}
int menu(int d){
	switch(d){
		case 0:
			return 1;
			break;
		case 1:
			createTabulaTab();
			break;
		case 2:
			createTabulaSpace();
			break;
		case 3:
			version();
			break;
		default:
			cout << "The answer is wrong BOB!" << endl;
			break;
	}
}
int main()
{
	int decision = 0;
	int ex = 0;

	while(ex == 0)
	{
		cout << "This program creates a Tabula Recta" << endl;
		cout << "\nMenu:\n" << endl;
		cout << "  1   Create Tabula Recta Tab-delimited" << endl;
		cout << "  2   Create Tabula Recta Space-delimited" << endl;
		cout << "  3   Version information" << endl;
		cout << "  0   Exit" << endl;
		cout << "\nEnter a Number: ";
		cin >> decision;
		ex = menu(decision);
	}
}
